package com.chatgpt.platformbasedchatgpt.service.impl;

import com.chatgpt.platformbasedchatgpt.service.SendMailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class SendMailServiceImpl implements SendMailService {

    @Resource
    private JavaMailSender javaMailSender;

    @Value("${spring.mail.username}")
    private String from ;


    @Override
    public void sendSimpleMail(String email,String checkCode) {

        String title = "【ChatGPT】您的验证信息邮件";
        String text = "亲爱的新用户，您的验证码："+checkCode+ " (2分钟内有效)。您正在使用邮箱验证码功能，验证码提供他人可能导致帐号被盗，请勿转发或泄漏。";

        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setTo(email);
        message.setSubject(title);
        message.setText(text);
        javaMailSender.send(message);
    }
}
